<template>
  <zm-dialog :title="pTitle" :visible.sync="value" append-to-body size="small" :before-close="dialogClose" :close-on-click-modal="false">
    <el-form :model="form" :rules="Rules" inline label-width="110px" label-position="left">
      <el-form-item label="接收对象：" prop="accountId" class="mb20">
        <el-cascader placeholder="接收对象" v-model="form.accountId" :props="props" :options="accountList" filterable clearable class="w200"></el-cascader>
      </el-form-item>
      <el-form-item label="备注信息：" prop="remark">
        <zm-input type="textarea" v-model="form.remark" placeholder="请输入备注信息" :autosize="{minRows: 3}" :maxlength="500" class="w400" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="tr">
      <el-button size="small" @click="dialogClose">取消</el-button>
      <el-button size="small" type="primary" @click="submit">确定</el-button>
    </div>
  </zm-dialog>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin'
import {getAccountList} from '@/api/src/public'
import {distributePublic} from '@/api/src/customer'

export default {
  mixins: [dialogMixin],
  props: {
    value: {
      type: Boolean,
      default: false
    },
    pTitle: {
      type: String,
      default: ''
    },
    nos: {
      type: String,
      default: ''
    },
    trans: {
      type: Boolean,
      default: false
    },
    props: {
      type: Object,
      default () {
        return {
          label: 'name',
          value: 'id',
          children: 'accountData'
        }
      }
    }
  },
  data () {
    return {
      form: {
        accountId: '',
        remark: ''
      },
      Rules: {
        accountId: {required: true, message: '选择接收对象', trigger: 'change'},
        remark: {required: true, message: '请输入备注信息', trigger: 'blur'}
      },
      accountList: []
    }
  },
  created () {
    this.init()
  },
  methods: {
    async init () {
      this.accountList = await getAccountList()
    },
    async submit () {
      const form = { ...{remark: this.form.remark}, ...{accountId: this.form.accountId[1]}, ...{ customerIds: this.nos } }
      await distributePublic(form)
      this.$message.success(`${this.pTitle}成功`)
      this.$emit('after')
      this.dialogClose()
    }
  }
}
</script>
